﻿<template>
	<div class="diDeliverData-container">
		<el-dialog v-model="state.isShowDialog" draggable width="769px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" size="default" label-width="100px" :rules="rules"
				:disabled="true">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="用户Id" prop="aUId">
							<el-input v-model="state.ruleForm.auId" placeholder="请输入访问用户Id" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="信息流" prop="flowPId">
							<el-input v-model="state.ruleForm.flowPName" placeholder="请输入信息流平台" class="w100"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="回传ID" prop="clickId">
							<el-input v-model="state.ruleForm.clickId" placeholder="请输入信息流平台回传的ID" class="w100"
								clearable maxlength="255" :autosize="{ minRows: 2 }" type="textarea" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="推广ID" prop="pid">
							<el-input v-model="state.ruleForm.pid" placeholder="请输入推广ID" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="触点配置" prop="toucherProductId">
							<el-input v-model="state.ruleForm.toucherProductId" placeholder="请输入触点产品配置" class="w100"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="回传类型" prop="deliverType">
							<el-input v-model="state.ruleForm.deliverType" placeholder="请输入信息流回传类型" class="w100"
								clearable />
						</el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="手机号码" prop="phone">
							<el-input v-model="state.ruleForm.phone" placeholder="请输入手机号码" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="推广渠道" prop="customerChannelId">
							<el-input v-model="state.ruleForm.customerChannelId" placeholder="请输入渠道id即客户提供的推广渠道参数"
								class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="回传状态" prop="deliverStatus">
							<el-input v-model="state.ruleForm.deliverStatus" placeholder="请输入信息流回传状态" class="w100"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="回传时间" prop="deliverTime">
							<el-input v-model="state.ruleForm.deliverTime" placeholder="请输入信息流回传时间传" class="w100"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="回传应答" prop="resData">
							<el-input v-model="state.ruleForm.resData" placeholder="请输入回传应答数据" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="请求IP" prop="requestIP">
							<el-input v-model="state.ruleForm.requestIP" placeholder="请输入请求IP" class="w100" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="IP位置" prop="iPLocation">
							<el-input v-model="state.ruleForm.iPLocation" placeholder="请输入IP位置" class="w100"
								clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="UserAgent" prop="userAgent">
							<el-input v-model="state.ruleForm.userAgent" placeholder="请输入UserAgent" class="w100"
								clearable maxlength="255" :autosize="{ minRows: 2 }" type="textarea" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="信息链接" prop="deliverUrl">
							<el-input v-model="state.ruleForm.deliverUrl" placeholder="请输入信息流回链接" class="w100" clearable
								maxlength="255" :autosize="{ minRows: 2 }" type="textarea" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="当前链接" prop="currentLink">
							<el-input v-model="state.ruleForm.currentLink" placeholder="请输入当前链接" class="w100" clearable
								maxlength="255" :autosize="{ minRows: 2 }" type="textarea" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="备注" prop="remark">
							<el-input v-model="state.ruleForm.remark" placeholder="请输入备注" class="w100" clearable
								maxlength="255" :autosize="{ minRows: 2 }" type="textarea" />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" size="default">关 闭</el-button>
					<!-- <el-button type="primary" @click="submit" size="default">确 定</el-button> -->
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="editDiDeliverData">
import { reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import type { FormRules } from "element-plus";
import mittBus from '/@/utils/mitt';
import { optionDict } from '/@/const/dict';
import { DiDeliverData } from '/@/api/models';
import SysDiDeliverDataApi from '/@/api/delivery/deliverData';

// 定义变量内容
const props = defineProps({
	title: String,
});
const ruleFormRef = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {} as DiDeliverData,
});

// 删除非必填规则.
const rules = ref<FormRules>({

});

// 打开弹窗.
const openDialog = (row: DiDeliverData) => {
	state.ruleForm = JSON.parse(JSON.stringify(row));
	state.isShowDialog = true;

	optionDict.backfillingStatus.map(item => {
		state.ruleForm.deliverStatus == item.value ? state.ruleForm.deliverStatus = item.label : state.ruleForm.deliverStatus;
	})
	optionDict.pageAccess.map(item => {
		state.ruleForm.deliverType == item.value ? state.ruleForm.deliverType = item.label : state.ruleForm.deliverType;
	})


};



// 关闭弹窗
const closeDialog = () => {
	mittBus.emit('submitRefresh');
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean, fields?: any) => {
		if (valid) {
			let res;
			if (state.ruleForm.id != undefined && state.ruleForm.id > 0) {
				res = await SysDiDeliverDataApi().editPost(state.ruleForm);
			} else {
				res = await SysDiDeliverDataApi().addPost(state.ruleForm);
			}
			if (res.data.resCode != '0000')
				ElMessage.error(res.data.resMessage);
			else {
				ElMessage.success("操作成功");
				closeDialog();
			}
		} else {
			ElMessage({
				message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
				type: "error",
			});
		}
	});
};

// 导出对象 将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
